<?php

declare(strict_types=1);

namespace Modules\Production\Models;

use Catch\Base\CatchModel as Model;

/**
 * @property $id
 * @property $production_order_id
 * @property $sort
 * @property $process_code
 * @property $process_name
 * @property $parent_id
 * @property $creator_id
 * @property $created_at
 * @property $updated_at
 * @property $deleted_at
*/
class ProductionProcess extends Model
{


    protected $table = 'production_process';

    protected $fillable = [ 'id', 'production_order_id', 'sort', 'process_code', 'process_name', 'parent_id','make_qty','total_hours', 'creator_id', 'created_at', 'updated_at', 'deleted_at' ];

    /**
     * @var array
     */
    protected array $fields = ['id','production_order_id','sort','process_code','process_name','parent_id','make_qty','total_hours','created_at','updated_at'];

    /**
     * @var array
     */
    protected array $form = ['id','production_order_id','sort','process_code','process_name','parent_id','make_qty','total_hours','created_at','updated_at'];

    /**
     * @var array
     */
    public array $searchable = [
        'production_order_id' => '=',
        'process_code' => '=',
        'process_name' => 'like',
        'parent_id' => '=',

    ];

    public function getFields(){
        return $this->fields;
    }

    /**
     * 时间格式化
     * @param $date
     * @return mixed
     */
    protected function serializeDate($date)
    {
        return $date->format('Y-m-d H:i');
    }

    /**
     * 关联生产工单头信息
     * @return mixed
     */
    public function order(){
        return $this->belongsTo(ProductionOrder::class,'production_order_id');
    }

    /**
     * 关联工序汇报明细
     * @return mixed
     */
    public function detail(){
        return $this->hasMany(ProductionProcessDetail::class,'process_id','id');
    }


}
